/** @type { import('webpack') } */
const webpack = require('webpack');
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const config = {
  mode: 'development',
  entry: [
    // 'react-hot-loader/patch',
    './src/index.tsx'
  ],
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'index.js'
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        use: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        // exclude: /node_modules/
      },
      {
          test: /\.css$/,
          use: [
              'style-loader',
              'css-loader',
          ]
      }
    ]
  },
  devServer: {
    port: 2020,
    hot: true,
  },
  plugins: [
    new webpack.CleanPlugin(),
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, 'public', 'index.html'),
      filename: 'index.html',
    }),
  ],
  resolve: {
    extensions: [
      '.tsx',
      '.ts',
      '.js',
      '.jsx',
    ],
  }
};

module.exports = config;
